#include "lc_op2_Operator.h"
#include "TCP_Packet.hh"

void 
op2::handleMyPort(pktTypes::IP_Packet * data, unsigned long dataSize)
{
  assert(data != NULL);
  pktTypes::TCP_Packet tcpPkt(*data);
  tt::IPAddress srcAddr(data->getSrcAddr());
  //  std::cout << "SRC: " << srcAddr << std::endl;
  uint32_t newaddr = 0x0;
  newaddr = newaddr | (192 << 24);
  newaddr = newaddr | (168 << 16);
  newaddr = newaddr | (100 << 8);
  newaddr = newaddr | 203;
  data->setSrcAddr(newaddr);
  data->setDstAddr(srcAddr.getIR());
  data->chksum();
  tcpPkt.chksum();
  
  tt::IPAddress srcNewAddr(data->getSrcAddr());
  //  std::cout << "NEW SRC: " << srcNewAddr << std::endl;
  //  std::cout << "NEW DST: " << srcAddr << std::endl;
  assert(data != NULL);
  normal(data, dataSize);
  return;
}

pktTypes::IP_Packet *
op2::geninRequest() 
{
  char * buff = new char[512];
  pktTypes::IP_Packet * data = new pktTypes::IP_Packet(buff, sizeof(buff));
  uint32_t newaddr = 0x0;
  newaddr = newaddr | (192 << 24);
  newaddr = newaddr | (168 << 16);
  newaddr = newaddr | (100 << 8);
  newaddr = newaddr | 203;
  data->setSrcAddr(newaddr);
  data->setDstAddr(newaddr + 1);
  data->chksum();
  return data;
}

